import { urlconstant } from '../../constant/index';
import { get, post } from '../../common/httptools.js';

// 获取会员信息
export const getMemberInfo = async () => {
  try {
    const res = await get(urlconstant.PLUS_MEMBER.GET_MEMBER_INFO);
    return res;
  } catch (error) {
    console.error('获取会员信息失败', error);
    throw error;
  }
};

// 购买会员
export const purchaseMembership = async (data) => {
  try {
    const res = await post(urlconstant.PLUS_MEMBER.PURCHASE_MEMBERSHIP, data);
    return res;
  } catch (error) {
    console.error('购买会员失败', error);
    throw error;
  }
};

// 获取购买历史
export const getPurchaseHistory = async (params = {}) => {
  try {
    const res = await get(urlconstant.PLUS_MEMBER.GET_PURCHASE_HISTORY, params);
    return res;
  } catch (error) {
    console.error('获取购买历史失败', error);
    throw error;
  }
};

// 续订会员
export const renewMembership = async (data) => {
  try {
    const res = await post(urlconstant.PLUS_MEMBER.RENEW_MEMBERSHIP, data);
    return res;
  } catch (error) {
    console.error('续订会员失败', error);
    throw error;
  }
};

// 取消会员
export const cancelMembership = async () => {
  try {
    const res = await post(urlconstant.PLUS_MEMBER.CANCEL_MEMBERSHIP);
    return res;
  } catch (error) {
    console.error('取消会员失败', error);
    throw error;
  }
};

// 获取会员权益详情
export const getMemberBenefits = async () => {
  try {
    const res = await get(urlconstant.PLUS_MEMBER.GET_BENEFITS);
    return res;
  } catch (error) {
    console.error('获取会员权益详情失败', error);
    throw error;
  }
};

// 购买星钻
export const purchaseDiamonds = async (data) => {
  try {
    const res = await post(urlconstant.PLUS_MEMBER.PURCHASE_DIAMONDS, data);
    return res;
  } catch (error) {
    console.error('购买星钻失败', error);
    throw error;
  }
};